<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_bootstrap.inc"%>
<title>${module.moduleName}</title>
</head>
	<body class="FrameRightBg">
	<!-- 表格列表 -->
	<div class="FrameRight" id="FrameRightContent">
		<div class="FrameRightInner mlzjhzdlb-default">
			<!-- location --> 
			<div class="main">
				<div id="standardSearchForm">
					<%@ include file="/WEB-INF/jsp/module/view/new_selector_form.jsp"%>
					<form id="formsearch" method="post">
						<input type="hidden" name="${module.module}list" id="${module.module}list"
							class="field" />
						<div class="selector-form"></div>
					</form>
				</div>
	
				<div class="common-option">
					<div class="inner">
												<button type="button"  class="btn btn-icon" onclick="StandardTable.goDetailPage()"><i class="icon iconfont icon-icon-plus"></i>企业新增</button>
						<button type="button"  class="btn btn-icon" onclick="StandardTable.modifyDetailPage()"><i class="icon iconfont icon-icon-edit"></i>企业修改</button>
						<button type="button"  class="btn btn-icon" onclick="StandardTable.stopLab()"><i class="icon iconfont icon-icon-plus"></i>企业暂停</button>
						<button type="button"  class="btn btn-icon" onclick="StandardTable.restoreLab()"><i class="icon iconfont icon-icon-plus"></i>企业恢复</button>
					</div> 
				</div>
	
				<div class="common-table">
					<table id="listTable" class="table table-hover"></table>
				</div>
			</div>
			<!-- main end -->
		</div>
		<!-- FrameRightInner -->
	</div>
	<!-- FrameRight -->
	<script type="text/javascript" src="${baseURL}/js/module/bootstrap/common_list.js"></script>
	<script>
  	var win = parent || window;
  	var selector;
  	
	StandardTable = {
		/* 跳转详情页 */
		goDetailPage: function(){
			parent.f_addTab("editCompany", '新增企业帐号', "${baseURL}/company/companyedit/superEdit.do?mdId=${param.mdId}&mdCode=${param.mdCode}&menuId=${param.menuId}&random="+Math.random());
		},
		//修改
		modifyDetailPage: function(){
			var selection = $("#listTable").bootstrapTable('getSelections');
			if(selection.length==1){
				var row = selection[0];
				parent.f_addTab("editCompany", '修改企业帐号', "${baseURL}/company/companyedit/superEdit.do?mdId=${param.mdId}&mdCode=${param.mdCode}&menuId=${param.menuId}&id="+row.id+"&"+Math.random());
 			}else{
				BT.showWarning("请选中一行！"); 
			}
		},
		/* 机构暂停 */	
		stopLab: function(){
			var selections = $("#listTable").bootstrapTable('getSelections');
			if(selections.length>0){
				BT.showConfirm("暂停","你确定要暂停所选的机构吗？",function(){
					var ids = "";
					for(var i=0; i<selections.length; i++){
						ids = ids + selections[i].id + ",";
						if(selections[i].status == 0){
							BT.showWarning("您选择的数据里包括已被停用的机构!");
							return false;
						}
					}
					ids = ids.substring(0,ids.length-1);
					$.ajax({
						type: "POST",
						url:"${baseURL}/company/companyedit/editStatus.do?mdCode=${param.mdCode}",
						dataType:'json',
						data:{ids:ids,status:0},
						success:function(data){
							if(data && data.hasOk == true){
								BT.showSuccess("提交成功!",function(){
									$("#listTable").bootstrapTable("refresh");
								});
							}else{
								BT.showError("提交出错!"+data.message);
							}
						}
					});
				}) 
 			}else{
				BT.showWarning("请至少选中一行！"); 
			}
		},
		/* 机构恢复 */
		restoreLab: function(){
			var selections = $("#listTable").bootstrapTable('getSelections');
			if(selections.length>0){
				BT.showConfirm("恢复","你确定要恢复所选的机构吗？",function(){
					var ids = "";
					for(var i=0; i<selections.length; i++){
						ids = ids + selections[i].id + ",";
					}
					ids = ids.substring(0,ids.length-1);
					$.ajax({
						type: "POST",
						url:"${baseURL}/company/companyedit/editStatus.do?mdCode=${param.mdCode}",
						dataType:'json',
						data:{ids:ids,status:1},
						success:function(data){
							if(data && data.hasOk == true){
								BT.showSuccess("提交成功!",function(){
									$("#listTable").bootstrapTable("refresh");
								});
							}else{
								BT.showError("提交出错!"+data.message);
							}
						}
					});
				}) 
 			}else{
				BT.showWarning("请至少选中一行！"); 
			}
		},
		//删除
		deleteByIds: function(){
			var selections = $("#listTable").bootstrapTable('getSelections');
			if(selections.length>0){
				BT.showConfirm("删除","你确定删除所选信息吗？",function(){
					var ids = "";
					for(var i=0; i<selections.length; i++){
						ids = ids + selections[i].id + ",";
					}
					ids = ids.substring(0,ids.length-1);
					$.ajax({
						type: "POST",
						url:"${baseURL}/jdbc/common/basecommondelete/delete.do?mdId=${param.mdId}&mdCode=${param.mdCode}",
						dataType:'json',
						data:{ids:ids},
						success:function(data){
							if(data && data.hasOk == true){
								BT.showSuccess("删除成功!",function(){
									$("#listTable").bootstrapTable("refresh");
								});
							}else{
								BT.showError("操作出错!"+data.message);
							}
						}
					})
				}) 
 			}else{
				BT.showWarning("请至少选中一行！"); 
			}
		},
		importEvent:function(){
			$('#importModal input[name=attachName]').val('');
			$('#importModal input[name=attach]').val('');
			$('#importModal #upload_error').html('');
			$('#importModal').modal();
		},
		exportEvent:function(){
			var selection = $("#listTable").bootstrapTable('getSelections');
	     	if (!selection || !selection.length) {
	     		if(selector != null){
	     			var data = $("#listTable").bootstrapTable('getOptions').queryParams();
	     			var searchParam = data.searchParam || '[]';
	     			var defaultSearchParam = data.defaultSearchParam || '[]';
	      			window.location.href = "${baseURL}/jdbc/common/basecommonlist/export.do?mdCode=${param.mdCode}&searchParam="+encodeURIComponent(encodeURIComponent(searchParam))+"&defaultSearchParam="+encodeURIComponent(encodeURIComponent(defaultSearchParam));
	     		}else{
	     			window.location.href = "${baseURL}/jdbc/common/basecommonlist/export.do?mdCode=${param.mdCode}";
	     		}
	     	}else{
	     		window.location.href = "${baseURL}/jdbc/common/basecommonlist/export.do?mdCode=${param.mdCode}&idslist="+BT.serialIdParam(selection);
	     	}
		},
		main: function(){
			var _this = StandardTable;
			_this.initTable();
			initSearchGrid($('#listTable'));
		}
	}
	
	$(function () {
		// 渲染选择器
		var defaultParams = [];
		<c:if test="${param.defaultParams!=null}">
	    var params = JSON.parse('${param.defaultParams}'||'{}');
	    for(var key in params){
	    	defaultParams.push({name:key,value:params[key],type:"exact-match"});
	    }
	    </c:if>
		var selectorData = JSON.parse('${module.selectorData}'||"[]",function(k,v){
			  if(v.indexOf&&v.indexOf('function')>-1){
				  return eval("(function(){return "+v+" })()");
			  }
			  return v;
			 });
		if (selectorData.length > 0) {
			var searchCondition = JSON.parse('${module.searchCondition}'||"[]");
			var searchGrid = {
				$element: $('#listTable'),
				load: function(){
					this.$element.bootstrapTable('refresh');
				}
			}
			selector = $.initSelector(searchGrid, selectorData, defaultParams, searchCondition);
		} else {
			$("#standardSearchForm").hide();
		}
		initListTable({
			module: {
				mdId: '${param.mdId}',
				mdCode: '${param.mdCode}',
				moduleDisplay: '${module.moduleDisplay}'
			},
			tableParams:{
				queryParams: function(params) {
					var data = [];
					if(selector != null){
						data = selector.getSelectorValue();
					}
					return {
						pageNo: params.pageNumber,
						perPageSize: params.pageSize,
						searchParam: JSON.stringify(data)
					}
				}
			}
		});
	});
	
	
	// 该方法用于给编辑页面刷新本页面
	function refreshTable(){
		$('#listTable').bootstrapTable('refresh'); 
	}
	</script>
</body>
</html>